<?php
	require_once("class.guestbook.php"); // Includes Class file.
	$guestbook = new guestbook(); // Start new object
	$guestbook->setFilename("guestbook.txt"); // set text file to use
	$guestbook->init(); // Can not remember
	$myGuests = $guestbook->getbook(); // make object of enterys
?>
<html>
	<head>
		<title>Guest Book</title>
		<style>
		.error{
			color:red;
		}
		</style>
	</head>
	<body>
		<form action="" method="POST">
			<input name="phpaction" type="hidden" value="true" />
			<table>
				<tr>
					<td>
						<?php foreach($guestbook->errors as $error): ?>
						<ul><li><?=$error?></li></ul>
						<?php endforeach; ?>
					</td>
				</tr>
				<tr>
					<td<?= (!isset($guestbook->errors['name']))? "" : " class='error'" ?>>Name:</td>
					<td><input name="name" type="text" /></td>
				</tr>
				<tr>
					<td>Email:</td>
					<td><input name="email" type="text" /></td>
				</tr>
				<tr>
					<td>Message:</td>
					<td><textarea name="message"></textarea></td>
				</tr>
				<tr>
					<td></td>
					<td><input name="submit" type="submit" value="Book Me" /></td>
				</tr>
			</table>
		</form>
		<hr />
		<ol>
			<?php foreach($myGuests as $guest): ?>
			<li><?=$guest[0]?> - <?=$guest[1]?><br />
				<p><?=$guest[2]?></p>
				<small><?=$guest[3]?></small><br />
			</li>
			<?php endforeach; ?>
		</ol>
	</body>
</html>